package zsc.ruanc.practicaltraining.controller;

import com.sun.activation.registries.MailcapFile;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import zsc.ruanc.practicaltraining.exception.ApiException;
import zsc.ruanc.practicaltraining.model.domain.TUser;
import zsc.ruanc.practicaltraining.model.result.JsonResult;
import zsc.ruanc.practicaltraining.model.result.ResultCode;
import zsc.ruanc.practicaltraining.service.Impl.UserServiceImpl;
import zsc.ruanc.practicaltraining.service.RabbitMQService;
import zsc.ruanc.practicaltraining.utils.DeleteUtils;
import zsc.ruanc.practicaltraining.utils.ResultUtils;

import java.io.File;
import java.io.IOException;

@RestController
@RequestMapping("/test")
@Api(tags = "测试类")
public class TestController {

    @Autowired
    private UserServiceImpl userService;

    @Autowired
    private RabbitMQService rabbitMQService;

    @Autowired
    DeleteUtils w;

    @GetMapping("/1efe32")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "a", value = "一个数", dataType = "Integer", paramType = "a"),
            @ApiImplicitParam(name = "b", value = "一个数", dataType = "Integer", paramType = "b"),
            @ApiImplicitParam(name = "c", value = "一个数", dataType = "Integer", paramType = "c")}
    )
    public String bo(int a, int b,int c) {
        return "wwwfee";
    }



//    @GetMapping("/test321/{id}")
//    public JsonResult k98(@PathVariable("id") int id) {
//        return ResultUtils.success(userService.selectById(id));
//    }

    @GetMapping("/opop")
    public JsonResult wf() {

        w.delete("888");
        return ResultUtils.success();
    }


    @PostMapping("/uploda")
    public JsonResult upload(MultipartFile file) throws IOException {
        if (file.getSize() > 50*1024*1024) {
            throw new ApiException(-9, "文件不能大于50MB");
        }
        file.transferTo(new File("/鬼刀/A/" + file.getOriginalFilename()));

        System.out.println("上传成功");
        return ResultUtils.success();
    }

    @PostMapping("/7878w")
    public JsonResult uplowad(@RequestBody TUser user) throws IOException {
        System.out.println(user);
        return ResultUtils.success();
    }

    @GetMapping("/okok")
    public JsonResult okok(@RequestParam int fromId, @RequestParam int toId, @RequestParam int articleId) {
        Long start = System.currentTimeMillis();
//        rabbitMQService.likesMailbox(fromId, toId,articleId);
        Long end = System.currentTimeMillis();
        System.out.println("--------------------------------");
        System.out.println("--------------------------------");
        System.out.println("--------------------------------");
        System.out.println("--------------------------------");
        System.out.println(end - start);
        return ResultUtils.success(end - start);
    }





}
